package net.lainiao.morethread.Chapter4.demo4;

import java.util.Random;
import java.util.concurrent.TimeUnit;

/**
 * Created by Administrator on 2017/3/3.
 */
public class UserValidator {
    private String name;

    public UserValidator(String name) {
        this.name = name;
    }

    public boolean validate(String name, String password) {
        Random random = new Random();
        long duration = (long) (Math.random() * 10);
        System.out.println("Validator " + this.name + " Validating a user during " + duration + " seconds");
        try {
            TimeUnit.SECONDS.sleep(duration);
        } catch (InterruptedException e) {
            return false;
        }
        return random.nextBoolean();
    }

    public String getName(){
        return this.name;
    }
}
